package com.spddr.pmos.jpa;

import javax.persistence.Column;
import javax.persistence.Convert;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.Table;

import org.joda.time.Period;

import cn.seqdata.jpa.JpaNoGeneratedObject;

import com.fasterxml.jackson.databind.annotation.JsonSerialize;

@Entity
@Table(name = "program_info")
public class Program extends JpaNoGeneratedObject {
	private static final long serialVersionUID = 1L;

	private ProgramType type;
	private TradeType tradeType;
	private EnergyType energyType;
	private Period interval;

	public Program() {
	}

	public Program(Long id) {
		super(id);
	}

	public Program(Long id, String name) {
		super(id, name);
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "type", nullable = false)
	@JsonSerialize(using = cn.seqdata.jackson.TypeSerializer.IdName.class)
	public ProgramType getType() {
		return this.type;
	}

	public void setType(ProgramType type) {
		this.type = type;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "trade_type", nullable = false)
	@JsonSerialize(using = cn.seqdata.jackson.TypeSerializer.IdName.class)
	public TradeType getTradeType() {
		return this.tradeType;
	}

	public void setTradeType(TradeType tradeType) {
		this.tradeType = tradeType;
	}

	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "energy_type", nullable = false)
	@JsonSerialize(using = cn.seqdata.jackson.TypeSerializer.IdName.class)
	public EnergyType getEnergyType() {
		return this.energyType;
	}

	public void setEnergyType(EnergyType energyType) {
		this.energyType = energyType;
	}

	@Column(name = "interval", nullable = false)
	@Convert(converter = cn.seqdata.jpa.converter.PeriodConverter.class)
	public Period getInterval() {
		return this.interval;
	}

	public void setInterval(Period interval) {
		this.interval = interval;
	}
}